package com.hrm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hrm.mapper.EmployeeMapper;
import com.hrm.pojo.Employee;
import com.hrm.request.FindEmployeeRequest;
import com.hrm.service.EmployeeService;
import com.hrm.vo.FindEmployeeVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Resource
    private EmployeeMapper employeeMapper;

    /**
     * 员工分页查询
     * @return
     */
    public Page<FindEmployeeVo> findEmployeeByInformations(FindEmployeeRequest findEmployeeRequest) throws Exception{

        if(findEmployeeRequest.getCurrentPage()!=null&&findEmployeeRequest.getPagesize()!=null){
            //设置分页信息
            PageHelper.startPage(findEmployeeRequest.getCurrentPage().intValue(),findEmployeeRequest.getPagesize().intValue());
        }
        return employeeMapper.findEmployeeByInformations(findEmployeeRequest);

    }

    @Override
    public boolean addEmployee(Employee employee) {
       if(employeeMapper.insertSelective(employee)<0)
           return false;
        return true;
    }

    @Override
    public Employee queryEmployee(Integer id) {

        return employeeMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean updateEmployee(Employee employee) {
        if( employeeMapper.updateByPrimaryKeySelective(employee)<0 )
            return false;
        return true;
    }

    @Override
    public boolean deleteEmployees(List<Integer> employeeIdList) {

        for (Integer id : employeeIdList) {
            if(employeeMapper.deleteByPrimaryKey(id)<=0)
                return false;
        }
        return true;
    }
}
